home *** CD-ROM | disk | FTP | other *** search
/ TOS Silver 2000 / TOS Silver 2000.iso / musik / MIDIFP21 / SOURCES / MY_LIB / GRAPHICS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-24  |  9.0 KB  |  320 lines

  1. /**************************************************************
  2. *
  3. *                GRAPHICS.C
  4. *
  5. **************************************************************/
  6.  
  7. #include <acs.h>
  8. #include <stdlib.h>
  9. #include <graphics.pif>
  10.  
  11. #define ELL_STRETCH 1.3   /* manipulation of ellipses in y-direction */
  12.  
  13.  
  14. /***************/
  15. void draw_note /*
  16. ****************/
  17. (
  18.     int handle,     /* VDI workstation handle */
  19.     int *points,    /* points[0]:     x-value of 1. corner
  20.                        points[1]:     y-value of 1. corner
  21.                        points[2]:     x-value of 2. corner
  22.                        points[3]:     y-value of 2. corner */
  23.     int type,       /* see below */
  24.     int style,         /* fill style */
  25.     int color        /* fill    color */
  26. )
  27. {
  28. register int hdl = handle ;
  29. register int dy = (points[3] - points[1])>>1, dy_ell = (int)( (float)dy * ELL_STRETCH ) ; 
  30. register int y_mean = (points[3] + points[1])>>1 ;
  31. register int p[6] ;
  32.  
  33. /*** Lenghty procedure, but optimized for speed ! ***/
  34.  
  35.     if (type & BODY_FRONT)
  36.     {
  37.         p[1] = points[1] - dy ; 
  38.         p[3] = points[3] + dy ;
  39.         p[5] = y_mean ;
  40.  
  41.         /*** draw in the background ***/
  42.         vsf_interior(hdl, FIS_SOLID) ;
  43.         vsf_color(hdl, BLACK) ;
  44.  
  45.         /*** draw head ***/
  46.         if (!(type & HEAD_CUT))
  47.         {    
  48.             p[2] = p[0] = points[0] ; 
  49.             if (type & HEAD_TRI) 
  50.             { 
  51.                 p[2] = p[0] = points[0] ; 
  52.                 p[4] = p[0] + points[3] - points[1] ;
  53.                 v_fillarea(hdl, 3, p) ; 
  54.             }
  55.             else if (type & HEAD_LINE) v_pline(hdl, 2, p) ; 
  56.         }    
  57.         /*** draw tail ***/
  58.         if (!(type & TAIL_CUT))
  59.         {
  60.             if (type & TAIL_TRI) 
  61.             { 
  62.                 p[2] = p[0] = points[2] ;
  63.                 p[4] = p[0] - points[3] + points[1] ;
  64.                 v_fillarea(hdl, 3, p) ; 
  65.             }
  66.             else if (type & TAIL_LINE) 
  67.             { 
  68.                 p[2] = p[0] = points[2] ; 
  69.                 v_pline(hdl, 2, p) ; 
  70.             }
  71.         }
  72.         /*** draw note body in the foreground ***/
  73.         if (!style) vsf_interior(hdl, FIS_HOLLOW) ;
  74.         else 
  75.         {
  76.             vsf_interior(hdl, FIS_PATTERN) ;
  77.             vsf_style(hdl, style) ;
  78.         }
  79.         vsf_color(hdl, color) ;
  80.         if (type & BODY_ELLIP) 
  81.         {
  82.             if (type & HEAD_CUT)
  83.             {
  84.                 v_ellpie(hdl, points[0], y_mean, points[2] - points[0], dy_ell, 2700, 900) ;
  85.                 if (color != BLACK)
  86.                 {
  87.                     vsf_interior(hdl, FIS_HOLLOW) ;
  88.                     vsf_color(hdl, BLACK) ;
  89.                     vswr_mode(hdl, MD_TRANS) ;
  90.                     v_ellpie(hdl, points[0], y_mean, points[2] - points[0], dy_ell, 2700, 900) ;
  91.                     vswr_mode(hdl, MD_REPLACE) ;
  92.                 }
  93.             }
  94.             else if (type & TAIL_CUT)
  95.             {
  96.                 v_ellpie(hdl, points[2], y_mean, points[2] - points[0], dy_ell, 900, 2700) ;
  97.                 if (color != BLACK)
  98.                 {
  99.                     vsf_interior(hdl, FIS_HOLLOW) ;
  100.                     vsf_color(hdl, BLACK) ;
  101.                     vswr_mode(hdl, MD_TRANS) ;
  102.                     v_ellpie(hdl, points[2], y_mean, points[2] - points[0], dy_ell, 900, 2700) ;
  103.                     vswr_mode(hdl, MD_REPLACE) ;
  104.                 }
  105.             }
  106.             else
  107.             {
  108.                 v_ellipse(hdl, (points[0] + points[2])>>1, y_mean, (points[2] - points[0])>>1, dy_ell) ;
  109.                 if (color != BLACK)
  110.                 {
  111.                     vsf_interior(hdl, FIS_HOLLOW) ;
  112.                     vsf_color(hdl, BLACK) ;
  113.                     vswr_mode(hdl, MD_TRANS) ;
  114.                     v_ellipse(hdl, (points[0] + points[2])>>1, y_mean, (points[2] - points[0])>>1, dy_ell) ;
  115.                     vswr_mode(hdl, MD_REPLACE) ;
  116.                 }
  117.             }
  118.         }
  119.         else if (type & BODY_RECT) 
  120.         {
  121.             v_bar(hdl, points) ;
  122.             if (color != BLACK)
  123.             {
  124.                 vsf_interior(hdl, FIS_HOLLOW) ;
  125.                 vsf_color(hdl, BLACK) ;
  126.                 vswr_mode(hdl, MD_TRANS) ;
  127.                 v_bar(hdl, points) ;
  128.                 vswr_mode(hdl, MD_REPLACE) ;
  129.             }
  130.         }
  131.     }
  132.     else
  133.     {
  134.         /*** draw note body in the background ***/
  135.         vsf_interior(hdl, FIS_SOLID) ;
  136.         vsf_color(hdl, BLACK) ;
  137.         if (type & BODY_ELLIP) 
  138.         {
  139.             dy = (points[3] - points[1])>>1 ;
  140.             y_mean = (points[3] + points[1])>>1 ; 
  141.             if (type & HEAD_CUT)
  142.                 v_ellpie(hdl, points[0], y_mean, points[2] - points[0], dy_ell, 2700, 900) ;
  143.             else if (type & TAIL_CUT)
  144.                 v_ellpie(hdl, points[2], y_mean, points[2] - points[0], dy_ell, 900, 2700) ;
  145.             else
  146.                 v_ellipse(hdl , (points[0] + points[2])>>1, y_mean, (points[2] - points[0])>>1, dy_ell) ;
  147.         }
  148.         else if (type & BODY_RECT) v_bar(hdl, points) ;
  149.  
  150.         /*** draw tail and head ***/
  151.         p[1] = points[1] - dy ; 
  152.         p[3] = points[3] + dy ;
  153.         p[5] = y_mean ;
  154.  
  155.         /*** draw tail ***/
  156.         if (!(type & TAIL_CUT))
  157.         {
  158.             if (type & TAIL_TRI) 
  159.             { 
  160.                 p[2] = p[0] = points[2] ;
  161.                 p[4] = p[0] - points[3] + points[1] ;
  162.                 if (!style) vsf_interior(hdl, FIS_HOLLOW) ;
  163.                 else 
  164.                 {
  165.                     vsf_interior(hdl, FIS_PATTERN) ;
  166.                     vsf_style(hdl, style) ;
  167.                 }
  168.                 vsf_color(hdl, color) ;
  169.                 v_fillarea(hdl, 3, p) ; 
  170.                 if (color != BLACK)
  171.                 {
  172.                     vsf_interior(hdl, FIS_HOLLOW) ;
  173.                     vsf_color(hdl, BLACK) ;
  174.                     vswr_mode(hdl, MD_TRANS) ;
  175.                     v_fillarea(hdl, 3, p) ; 
  176.                     vswr_mode(hdl, MD_REPLACE) ;
  177.                 }
  178.             }
  179.             else if (type & TAIL_LINE) 
  180.             { 
  181.                 p[2] = p[0] = points[2] ; 
  182.                 v_pline(hdl, 2, p) ; 
  183.             }
  184.         }
  185.         /*** draw head ***/
  186.         if (!(type & HEAD_CUT))
  187.         {    
  188.             p[2] = p[0] = points[0] ; 
  189.             if (type & HEAD_TRI) 
  190.             { 
  191.                 p[2] = p[0] = points[0] ; 
  192.                 p[4] = p[0] + points[3] - points[1] ;
  193.                 if (!style) vsf_interior(hdl, FIS_HOLLOW) ;
  194.                 else 
  195.                 {
  196.                     vsf_interior(hdl, FIS_PATTERN) ;
  197.                     vsf_style(hdl, style) ;
  198.                 }
  199.                 vsf_color(hdl, color) ;
  200.                 v_fillarea(hdl, 3, p) ; 
  201.                 if (color != BLACK)
  202.                 {
  203.                     vsf_interior(hdl, FIS_HOLLOW) ;
  204.                     vsf_color(hdl, BLACK) ;
  205.                     vswr_mode(hdl, MD_TRANS) ;
  206.                     v_fillarea(hdl, 3, p) ; 
  207.                     vswr_mode(hdl, MD_REPLACE) ;
  208.                 }
  209.             }
  210.             else if (type & HEAD_LINE) v_pline(hdl, 2, p) ; 
  211.         }    
  212.     }
  213. }
  214.  
  215.  
  216. /****************/
  217. void draw_lines /*
  218. *****************/
  219. (
  220.     int handle,             /* VDI workstation handle */
  221.     char number,            /* number of lines to be drawn */
  222.     char first_marked,         /* first line with special marking */
  223.     char d_marked,             /* special marking each d_marked lines */
  224.     MARK_MODE mode,         /* where to place rectangle marks */
  225.     int styles[12],         /* styles to be used after a special line */
  226.     int colors[12],         /* colors to be used after a special line */
  227.     char first_number,      /* number (text) for first special line */
  228.     int number_dots,        /* of special line, no dots if -1 */
  229.     int dx_text,             /* text (number) offset from x_start on */
  230.     int dy_text,            /* text (number) offset from y_start on */
  231.     int x_start,             /* of first line */
  232.     int y_start,            /* of first line */
  233.     int x_end,                 /* of first line */
  234.     int y_end,                /* of first_line */
  235.     float dx,                 /* distance of succeeding lines */
  236.     float dy                /* distance of succeeding lines */
  237. {
  238. char i, number_offset, k ; 
  239. int points[4], dx_m = (int)(dx * d_marked / 12), 
  240.                dy_m = (int)(dy * d_marked / 12) ; 
  241. int x_width, y_width, color, style ;
  242. char *dummy = "--" ; 
  243.  
  244.     number_offset = 11 ;
  245.     color = colors[(first_number + number_offset) % 12] ;
  246.     vsl_color(handle, color) ;
  247.     number_offset = -1 ;
  248.     
  249.     for (i = 0 ; i < number ; i ++ )
  250.     {
  251.         points[0] = (int)(dx * i) + x_start ; 
  252.         points[1] = (int)(dy * i) + y_start ;
  253.         points[2] = points[0] + x_end - x_start ; 
  254.         points[3] = points[1] + y_end - y_start ;
  255.  
  256.         if (i % d_marked != first_marked) v_pline(handle, 2, points) ;
  257.         else 
  258.         {
  259.             /*** switch to next color and style ***/
  260.             number_offset ++ ;
  261.             color = colors[(first_number + number_offset) % 12] ;
  262.             style = styles[(first_number + number_offset) % 12] ;
  263.             vsl_color(handle, color) ;
  264.             vsf_color(handle, color) ;
  265.             vsf_style(handle, style) ;
  266.     
  267.             if (first_marked == -1) v_pline(handle, 2, points) ;
  268.             else
  269.             {
  270.                 /*** mark with number ***/
  271.                 v_gtext( handle, points[0] + dx_text, points[1] + dy_text, 
  272.                          itoa(first_number + number_offset, dummy, 12) ) ;
  273.                          
  274.                 if (style == IP_HOLLOW) vsl_width(handle, 3) ;
  275.                 if (number_dots <= 0)
  276.                     if (mode == behind)
  277.                     {
  278.                         /*** mark non-dotted, rectangle behind line ***/
  279.                         points[0] += dx_m ; points[1] += dy_m ; points[2] -= dx_m ; points[3] -= dy_m ; 
  280.                         if (style != IP_HOLLOW) v_bar(handle, points) ;
  281.                         
  282.                         points[0] -= dx_m ; points[1] -= dy_m ; points[2] += dx_m ; points[3] += dy_m ; 
  283.                         v_pline(handle, 2, points) ;                    
  284.                     }
  285.                     else 
  286.                     {
  287.                         /*** mark non-dotted, rectangle between lines ***/
  288.                         points[0] += dx ; points[1] += dy ;
  289.                         if (i != number - 1) if (style != IP_HOLLOW) v_bar(handle, points) ;
  290.  
  291.                         points[0] -= dx ; points[1] -= dy ;
  292.                         v_pline(handle, 2, points) ;                    
  293.                     }
  294.                 else 
  295.                 {
  296.                     x_width = ((x_end - x_start) / number_dots) >> 1 ;
  297.                     y_width = ((y_end - y_start) / number_dots) >> 1 ;
  298.                     for (k = 0 ; k < number_dots ; k++)
  299.                     {
  300.                         /*** draw dot ***/
  301.                         points[0] = (int)(dx * i) + x_start 
  302.                                     + (long)(x_end - x_start) * k / number_dots + dx_m ; 
  303.                         points[1] = (int)(dy * i) + y_start 
  304.                                     + (long)(y_end - y_start) * k / number_dots + dy_m ;
  305.                         points[2] = points[0] + x_width - (dx_m << 1) ;
  306.                         points[3] = points[1] + y_width - (dy_m << 1) ;
  307.                         if (style != IP_HOLLOW) v_bar(handle, points) ;
  308.                     
  309.                         points[0] -= dx_m ; points[1] -= dy_m ; points[2] += dx_m ; points[3] += dy_m ; 
  310.                         v_pline(handle, 2, points) ;                    
  311.                     }
  312.                 }
  313.                 /*** reset line width ***/
  314.                 vsl_width(handle, 1) ;
  315.             }
  316.         }
  317.     }
  318. }
  319.